package com.GameSpace.CoreAssets;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;


public class OptionManager{

	public OptionsDBAdapter dbAdapter;
	
	public OptionManager(){
		
	}
	
	public OptionManager(Context ctx){
		dbAdapter=new OptionsDBAdapter(ctx);
	}
	
	public void addOption(Option o){		 
		
		dbAdapter.open();
		dbAdapter.insertOption(o);
		dbAdapter.close();
	}
	
	public void deleteOption(String optionLabel){
		dbAdapter.open();
		dbAdapter.deleteOption(optionLabel);
		dbAdapter.close();
	}
	
	public void updateOption(Option o){
		dbAdapter.open();
		dbAdapter.updateOption(o);
		dbAdapter.close();
	}
	
	public Option getOption(String optionLabel){
		dbAdapter.open();
		Cursor c = dbAdapter.getOption(optionLabel);
		Option o = new Option();
		while(c.moveToNext()){
			o.setType(c.getString(1));
			o.setLabel(c.getString(2));
			o.setValue(c.getString(3));
		}
		dbAdapter.close();
		return o;
	}
	
	public ArrayList<Option> getAllOptions(){
		
		ArrayList<Option> options;
		dbAdapter.open();
		Cursor c = dbAdapter.getAllOptions();
		options = new ArrayList<Option>();
		while(c.moveToNext()){
			Option o = new Option();
			o.setType(c.getString(1));
			o.setLabel(c.getString(2));
			o.setValue(c.getString(3));
			options.add(o);
		}
		dbAdapter.close();
		return options;
	}
	

}